//
//  UILabel+StringFrame.m
//  label文字左右移动
//
//  Created by longziyuan on 14-6-21.
//  Copyright (c) 2014年 longziyuan. All rights reserved.
//

#import "UILabel+StringFrame.h"

@implementation UILabel (StringFrame)

- (CGSize)boundingRectWithSize:(CGSize)size
{
    NSDictionary *attribute = @{NSFontAttributeName: self.font};
    
    CGSize retSize = [self.text boundingRectWithSize:size
                                             options:\
                      NSStringDrawingTruncatesLastVisibleLine |
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                          attributes:attribute
                                             context:nil].size;
    
    return retSize;
}

-(CGSize)getLabelSize
{
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    //设置一个行高上限
    CGSize size = CGSizeMake(1000,2000);
    //计算实际frame大小，并将label的frame变成实际大小
    CGSize labelSize = [self.text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    [self setFont:font];
    return labelSize;
    
}

@end
